# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=ocaml-atd
pkgver=2.15.0
pkgrel=0
_pkgreal=atd
pkgdesc="Adjustable Type Definitions"
url="https://github.com/ahrefs/atd"
arch="all !riscv64 !loongarch64" # ocaml
license="MIT"
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	ocaml-biniou-dev
	ocaml-easy-format-dev
	ocaml-re-dev
	ocaml-yojson-dev
	"
makedepends="
	$depends_dev
	dune
	ocaml
	ocaml-cmdliner-dev
	ocaml-menhir
	"
checkdepends="
	ocaml-alcotest-dev
	py3-jsonschema
	"
subpackages="$pkgname-dev"
source="$_pkgreal-$pkgver.tar.bz2::https://github.com/ahrefs/atd/releases/download/$pkgver/atd-$pkgver.tbz
	disable-ocaml-internals-test.patch
	"
builddir="$srcdir/$_pkgreal-$pkgver"

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	dune build --release --verbose
}

check() {
	dune runtest --build-dir=.testenv \
		-p atd,atdgen,atdgen-codec-runtime,atdgen-runtime,atdts
}

package() {
	dune install --destdir="$pkgdir" --docdir=/.omit
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find usr/lib/ocaml \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
33b7943ae6afd14e5a0709d9131d288e663d3f2b962caa065f1b11db8f6adfe081becba7968c8596b3ff2420577295ac248d521858cb0748e95971390eb29829  atd-2.15.0.tar.bz2
0b41d1224f770ca868c09548716c01a8c8f4508cd790f4d8b39afbc602365e197369d4d2fd766a6ab06d002e376e112525768b6b20b732ace6b56037f0b9f71d  disable-ocaml-internals-test.patch
"
